package com.jiang.daily.Q1561;

import java.util.Arrays;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/01/22 15:24
 */
class Solution {
    public int maxCoins(int[] piles) {
        Arrays.sort(piles);
        int l = 0, r = piles.length - 1;
        int res = 0;
        while (l < r) {
            res += piles[r - 1];
            l += 1;
            r -= 2;
        }
        return res;
    }
}
